package pers.archives.common.entity;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import pers.archives.common.ov.OVUser;

import java.io.Serializable;
import java.util.Collection;

/*
 *@program:archives-parent
 *@author: 赵浩浩
 *@Time: 2020/8/21  19:04
 */
@Data
@Slf4j
public class SecurityUser implements Serializable,  UserDetails{

    private static final long serialVersionUID = -200332617999708927L;

    private User currentUserInfo;


    public SecurityUser() { }

    public SecurityUser(User user) {
        this.currentUserInfo = user;
    }

    private String token;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return AuthorityUtils.commaSeparatedStringToAuthorityList("admin,ROLE_USER");
    }

    @Override
    public String getPassword() {
        return currentUserInfo.getPassword();
    }

    @Override
    public String getUsername() {
        return currentUserInfo.getUserName();
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }

}
